package com.example.natatorium_management.contorller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.natatorium_management.entity.DTO.GoodIds;
import com.example.natatorium_management.entity.Order;
import com.example.natatorium_management.entity.OrderGood;
import com.example.natatorium_management.result.restful.R;
import com.example.natatorium_management.service.OrderService;
import com.example.natatorium_management.service.impl.OrderGoodServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Order")
public class OrderController {

    @Autowired
    OrderService orderService;
    @Autowired
    OrderGoodServiceImpl orderGoodService;

    /**
     * 分页
     * @param current 1
     * @param size 1
     * @return 1
     */
    @GetMapping("/queryPage")
    public R<IPage<Order>> queryPage(int current, int size){
       return orderService.queryPage(current,size);
    }

    /**
     * 添加
     * @param order 1
     * @return 1
     */
    @PostMapping("/addOrder")
    public R<Order> addOrder(@RequestBody Order order){
        return orderService.addOrder(order);
    }

    /**
     * 删除
     * @param orderId 1
     * @return 1
     */
    @DeleteMapping("/deleteOrderById/{orderId}")
    public R<Order> deleteOrderById(@PathVariable("orderId") Integer orderId){
        return orderService.deleteOrderById(orderId);
    }

    /**
     * 更新订单
     * @param order 1
     * @return 1
     */
    @PutMapping("/updateOrder")
    public R<Order> updateOrder(@RequestBody Order order){
        return orderService.updateOrder(order);
    }

    /**
     * 查找
     * @param order 1
     * @param current 1
     * @param size 1
     * @return 1
     */
    @PostMapping("/findOrder")
    public R<IPage<Order>> findOrder(@RequestBody Order order,@RequestParam int current,@RequestParam int size){
        return orderService.findOrder(order,current,size);
    }
    @PostMapping("/addGoodInOrder")
    public R<OrderGood> addGoodInOrder(@RequestBody GoodIds goodIds, @RequestParam Long orderId){
        return orderGoodService.addGoodInOrder(goodIds.getGoodIds(),orderId);
    }


}
